package net.ankao.org.easylock.service.impl;

import net.ankao.org.easylock.annotation.EasyLock;
import net.ankao.org.easylock.entity.User;
import net.ankao.org.easylock.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * DemoServiceImpl
 * </p>
 *
 * @author lilu
 * @since 2022/3/28
 */
@Service
public class DemoServiceImpl implements DemoService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    @EasyLock(value = "#user.name",waitTime=2,condition = "#user.sex == '女' ")
    public Integer happyNewYear(User user) {
        Integer age = 1;
        String s = stringRedisTemplate.opsForValue().get(user.getName());
        if(StringUtils.hasText(s)){
            age += Integer.parseInt(s);
        }
        stringRedisTemplate.opsForValue().set(user.getName(),age.toString());
        return age;
    }

}
